<template>
  <div>
    <HomeHeader :city="city"></HomeHeader>
    <HomeSwiper :swlist="swiperList"></HomeSwiper>
    <HomeIcon></HomeIcon>
    <HomeRecommend :cardList="recommendList"></HomeRecommend>
    <HomeWeekend :weekendList="weekendList"></HomeWeekend>
  </div>
</template>


<script>
  import HomeHeader from './components/Header'
  import HomeSwiper from './components/Swiper'
  import HomeIcon from './components/Icon'
  import HomeRecommend from './components/Recommend'
  import HomeWeekend from './components/Weekend'
  import axios from 'axios'

  export default {
    name: 'Home',
    components: {
      HomeHeader,
      HomeSwiper,
      HomeIcon,
      HomeRecommend,
      HomeWeekend,
    },
    data() {
      return {
        city: "",
        swiperList: [],
        recommendList: [],
        weekendList: [],
        lastCity: "",
      }
    },
    methods: {
      getHomeInfo() {
        axios.get('/static/mock/index.json').then(this.getHomeInfoSucc)
      },
      getHomeInfoSucc(res) {
        res = res.data;
        if (res.ret && res.data) {
          const data = res.data;
          this.swiperList = res.data.swiperList;
          this.recommendList = res.data.recommendList;
          this.weekendList = res.data.weekendList;
        }
      }
    },
    mounted() {
      this.getHomeInfo();
      this.lastCity = this.city
    },
    activated() { // 当页面重新被显示时执行(频率高于mounted)
      if (this.lastCity !== this.city) {
        this.lastCity = this.city;
        this.getHomeInfo()
      }
    }

  }
</script>

